<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\admin\model;

use manniu\model\Base;

use app\admin\model\LinkageData;

class Linkage extends Base
{
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = true;
	// 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    /**
     * 更新缓存
     * @access public
     * @return void
     */
    public function cache(){
    	// 查询所有内容
        $linkages = $this->order(['id'=>'asc'])->select();
        foreach ($linkages as $linkage_k => $linkage_v) {
        	cache('linkage_'.$linkage_v->getAttr('id'), NULL);
        	$linkage_data = new LinkageData;
        	$linkage = $linkage_data->getTreeArray(0,$linkage_v->getAttr('id'));
        	if(!$linkage){
        		$linkage = NULL;
        	}
        	cache('linkage_'.$linkage_v->getAttr('id'), $linkage);
        }
    }
}